/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControllerLag;
import ModelLag.*;
import DBLag.*;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Ronni
 */
public class EmployeeCTR{
    private IFDbEmployee dbEmployee;

    public EmployeeCTR() {
    dbEmployee = new DbEmployee();
    }

    public int toggleActive(String cprNo) throws SQLException
    {
        try{
            return dbEmployee.toggleActive(cprNo);
        }catch(SQLException e)
        {
            throw new SQLException(e);
        }
    }

    public Employee findEmployee(String cprNo) {
        return dbEmployee.findEmployee(cprNo);
    }

    public ArrayList<Employee> searchEmployee(String searchString) {
        return dbEmployee.searchEmployee(searchString);
    }


    public ArrayList<Employee> getAllEmployees() {
        return dbEmployee.getAllEmployees();
    }

    public int createEmployee(String cprNo, String fName, String lName, String address, String zipCode, String email, String phoneNo,boolean active) throws SQLException
    {
        Employee newEmployee = new Employee(cprNo,fName,lName,address,zipCode,email,phoneNo,active);
        return dbEmployee.insertEmployee(newEmployee);
        
    }
    public int insertEmployee(Employee newEmployee) throws SQLException {
        int rc;
        try{
            rc = dbEmployee.insertEmployee(newEmployee);
        }catch(SQLException e){
            throw new SQLException(e);
        }
        return rc; 
    }


    public int updateEmployee(String cprNo, String fName, String lName, String address, String zipCode, String email, String phoneNo,boolean active) throws SQLException {
        Employee newEmployee = new Employee(cprNo,fName,lName,address,zipCode,email,phoneNo,active);
        int rc;
        try{
            rc = dbEmployee.updateEmployee(newEmployee);
        }catch(SQLException e)
        {
            throw new SQLException(e);
        }
        return rc;
    }


    public int deleteEmployee(String cprNo) throws SQLException {
        Employee newEmployee = new Employee();
        newEmployee.setCprNo(cprNo);
        int rc;
        try{
            rc = dbEmployee.deleteEmployee(newEmployee);
        }catch(SQLException e){
            throw new SQLException(e);
        }
        return rc;
    }
    
    



}

